package popup
{
	import components.ErrorPopup;
	
	
	import flash.display.DisplayObjectContainer;
	import flash.events.Event;
	
	import model.Modellocator;
	
	import mx.core.FlexGlobals;
	public class ErrorPopupCreator
	{
		private static var instance:ErrorPopupCreator;
		public var errorPopUp:ErrorPopup;
		public var optionalWindowToHide:Object;
		private var callBackFunction:Function;
		
		
		/* Error Messages */
		public var ERROR_TITLE:String					= "ERROR";
		public var INFORMATION_TITLE:String				= "INFORMATION";
		public var WARNING_TITLE:String					= "WARNING";
		
		public var INTERNET_CONNECTION_LOST:String		= 	"Check your internet connection";
		public var SOME_PROBLEM:String					= 	"There is some problem";
		public var MAX_LIMIT_REACHED:String				= 	"You have pending invitations \n Please clear some active games.";
		public var PASWORD_NOT_MATCH:String				=  	"Password not match\n";
		public var CONFIRM_NOT_MATCH:String				=  	"Confirm Password did not match";
		public var PASSWORD_NOT_ACCEPT:String			=  	"Password not acceptable\n";
		public var PASSWORD_LESS_CHARACTERS:String		=  	"Password should be between\n 5 and 10 characters";
		public var ALL_FIELDS_MANADATORY:String			=  	"Please enter the required information";
		public var INCORRECT_EMAIL:String				= 	"Please type correct Email";
		public var SERVER_ERROR:String					= 	"There was some problem from server";
		public var CREATE_VALID_CODE:String				= 	"Please enter valid code to guess"
		public var INVALID_USERNAME_PASSWORD:String		= 	"Username/Password is not correct";
		public var CONFIRM_EMAIL:String					= 	"Please confirm Email/ Confirmation link sent you via email";
		public var ACCOUNT_INACTIVE:String				= 	"Your account is inactive / Please call customer care";
		public var RESET_USERNAME:String				= 	"Username has been sent to \n Email address on file"
		public var RESET_PASSWORD:String				= 	"Password has been sent to \n Email address on file"
		public var RESET_CREDENTIALS:String				= 	"reset credentials has been sent to \n Email address on file"
		public var BNM_NO_ACCOUNT:String				= 	" don't have Bullets & Maggots account to Play";
		public var FACEBOOK_MSG:String					= 	" lets play Bullets & Maggots mine BNM User Name is : (";
		public var INVITAITON_SENT:String				= 	"Invitation sent "; 
		public var INVALID_SENT:String				    = 	"Invalid";
		
		public var SKU_EXISTS:String			= 	"Item with this barcode is already exist."; 
		public var MAX_INVITAITON_SENT_OWN:String			= 	"You have reached the maximum number of games. \n Please finish a game before creating a new game"; 
		
		public var ENTER_USERNAME:String                =   "Please enter some user name";
		
		public static function getInstance():ErrorPopupCreator{
			if (instance == null){
				instance = new ErrorPopupCreator();
			}
			return instance;
		}
		
		
		public function showErrorWindow(errorMessage:String, suggestedMessage:String, currentWidth:Number, optionalWindow:*, parentContainer:*, 
										resultBackFunction:Function = null ,titleStr:String = "ERROR", buttonLabel:String = "OK", buttonVisible:Boolean = true):void
		{
			errorPopUp = new ErrorPopup();
			errorPopUp.title = titleStr;
			errorPopUp.open(parentContainer, true);
			errorPopUp.width = 	currentWidth;
			errorPopUp.height = parentContainer.height/2.7;
			errorPopUp.x = parentContainer.width/2; 
			errorPopUp.y = parentContainer.height/2;
			errorPopUp.message.text = errorMessage;
			//errorPopUp.message.styleName = "errorMessageTitle";
			//errorPopUp.tmpMessage.text = suggestedMessage;
			if(suggestedMessage == "")
			{
				errorPopUp.tmpMessage.includeInLayout = false;
				errorPopUp.tmpMessage.visible = false;
			}
			if(buttonVisible == true)
			{
				errorPopUp.tryAgain.label = buttonLabel; 
				errorPopUp.addEventListener('try_again_pressed', handleTryAgain);
				errorPopUp.addEventListener('close_clicked', handleClose);
				callBackFunction = resultBackFunction;
			}
			else if(buttonVisible == false)
			{
				errorPopUp.addEventListener('close_clicked', handleClose);
				errorPopUp.tryAgain.includeInLayout = buttonVisible;
				errorPopUp.tryAgain.visible = buttonVisible;
			}
		}
		
		protected function handleTryAgain(event:Event):void{
			errorPopUp.close(true);
		}
		
		protected function handleClose(event:Event):void{
			errorPopUp.close(true);
		}
	}
}